package com.mccken.practice.temp;

import java.util.Stack;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2023-12-31 22:15
 **/
public class McckenQueue {
	
	Stack<Integer> stack1;
	Stack<Integer> stack2;

	public McckenQueue() {
		stack1 = new Stack<>();
		stack2 = new Stack<>();
	}
	
	public void push(int x) {
		stack1.push(x);
	}
	
	public int pop() {
		if (!stack2.empty()) {
			return stack2.pop();	
		}
		
		while (!stack1.empty()) {
			stack2.push(stack1.pop());
		}
		return stack2.pop();
	}
	
	public int peek() {
		if (!stack2.empty()) {
			return stack2.peek();
		}
		while (!stack1.empty()) {
			stack2.push(stack1.pop());
		}
		return stack2.peek();
	}


	public boolean empty() {
		return stack1.empty() && stack2.empty();
	}

	public static void main(String[] args) {
		McckenQueue myQueue = new McckenQueue();
		myQueue.push(1); // queue is: [1]
		myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
		myQueue.peek(); // return 1
		myQueue.pop(); // return 1, queue is [2]
		myQueue.empty(); // return false
	}
}
